using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

namespace KFGame
{

    /// <summary>
    /// 统计页
    /// </summary>
    public class KFStatitcsView : KFBackViewManager
    {

        public GameObject back;


        //选择的行
        int selectRow = 0;

        //总项数量
        int itemsCount = 0;

        int buttonnumb = 1;


        public KFStatitcsDataCharts charts;

        void Start()
        {
            initView();
            itemsCount = charts.getChartCount();
            itemsCount += buttonnumb;
        }

        public void toClose()
        {

            close();
        }

        /// <summary>
        /// 由框加推送的事件
        /// </summary>
        /// <param name="e"></param>
        public override void OnEvent(KFEvent e)
        {
            base.OnEvent(e);
            //向上
            if (e.name == KFEEVENTS.KFE_EVENT_TO_UP)
            {
                selectRow--;
                if (selectRow < 0)
                    selectRow = itemsCount - 1;

                selecNumber();
                return;
            }

            //向下
            if (e.name == KFEEVENTS.KFE_EVENT_TO_DOWN)
            {

                selectRow++;
                if (selectRow >= itemsCount)
                    selectRow = 0;

                selecNumber();
                return;
            }
            if (e.name == KFEEVENTS.KFE_EVENT_TO_OK)
            {
                onCheck();
            }
        }

        public void onCheck()
        {
            int sc = selectRow - buttonnumb;
            if (sc < 0)
            {
                toClose();
            }
        }
        public void selecNumber()
        {
            int sc = selectRow - buttonnumb;
            back.SetActive(false);
            if (sc < 0)
            {
                back.SetActive(true);
            }

            charts.select(sc);
        }
    }
}
